package com.guohui.boot1.config.interceptor;

import java.lang.reflect.Method;
import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class WebLogInterceptor extends HandlerInterceptorAdapter{
  
  private Logger logger = LoggerFactory.getLogger(getClass());

  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
      throws Exception {
    
//    HandlerMethod handlerMethod = (HandlerMethod) handler;
//    Method method = handlerMethod.getMethod();
//    
//    logger.info("INTERURL : " + request.getRequestURL().toString());
//    logger.info("INTERHTTP_METHOD : " + request.getMethod());
//    logger.info("INTERIP : " + request.getRemoteAddr());
//    logger.info("INTERCLASS_METHOD : " + method.getDeclaringClass() + "."
//        + method.getName());
//    logger.info("INTERARGS : " + Arrays.toString(method.getParameterTypes()));
    
    return super.preHandle(request, response, handler);
  }

  @Override
  public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
      ModelAndView modelAndView) throws Exception {
//    HandlerMethod handlerMethod = (HandlerMethod) handler;
//    Method method = handlerMethod.getMethod();
//    
//    logger.info("INTERRESPONSE : " + method.getReturnType());
    super.postHandle(request, response, handler, modelAndView);
  }

}
